﻿using RuoVea.ExEnum;

namespace RuoVea.WeighIns.Web.Controllers;

/// <summary>
/// 
/// </summary>
[Authorize]
public class UserSettingsController : Controller
{
    private readonly UserSettingsService _userSettingsService;
    public UserSettingsController(UserSettingsService userSettingsService)
    {  
        _userSettingsService = userSettingsService;
    }

    /// <summary>
    /// 
    /// </summary>
    /// <returns></returns>
    public IActionResult Index()
    {
        return View();
    }

    /// <summary>
    /// 获取用户设置
    /// </summary>
    [HttpGet("usersettings/info")]
    public async Task<RestfulResult<InsUserSettings>> GetUserSettingsAsync()
    {
        RestfulResult<InsUserSettings> restful = new() { Code = CodeStatus.OK };
        restful.Data= await _userSettingsService.GetUserSettingsAsync();
        return restful;
    }

    /// <summary>
    /// 更新用户设置
    /// </summary>
    [HttpPost("usersettings/update")]
    public async Task<RestfulResult> UpdateUserSettingsAsync([FromBody] UserSettingsDto dto)
    {
        RestfulResult restful = new() { Code = CodeStatus.OK };
        restful.Data= await _userSettingsService.UpdateUserSettingsAsync(dto);
        return restful;
    }

    /// <summary>
    /// 计算基础代谢率(BMR)
    /// </summary>
    [HttpGet("usersettings/calculatebmr")]
    public Task<RestfulResult> CalculateBMRAsync(InsUserSettings settings, double weight, double height, int age, int gender)
    {
        RestfulResult restful = new() { Code = CodeStatus.OK };
        restful.Data =  _userSettingsService.CalculateBMR(settings,   weight,   height,   age,   gender);
        return Task.FromResult(restful);
    }

    /// <summary>
    /// 计算每日总能量消耗(TDEE)
    /// </summary>
    [HttpGet("usersettings/calculatetdee")]
    public Task<RestfulResult> CalculateTDEEAsync(double bmr, int activityLevel)
    {
        RestfulResult restful = new() { Code = CodeStatus.OK };
        restful.Data =  _userSettingsService.CalculateTDEE(bmr,   activityLevel);
        return Task.FromResult(restful);
    }
}

